####################################################################
## author:    Robert A. Huber
## contact:   robert.huber@ir.gess.ethz.ch
## file name: pc_uk_descriptives.R
## Context:   Populism and Climate Sceptism, individuals from BES
## started:   2016-10-12
## Summary:   Descriptives
######################################################################

p_lrpop <- ggplot(df_bes, aes(x=lr, y=populism)) +
  geom_point() +
  geom_jitter() +
  geom_smooth() +
  theme_tufte() +
  xlab("Political ideology") + 
  ylab("Populist attitudes") +
  scale_x_continuous(breaks = c(seq(1:10)),  labels=c("Left", "2", "3", "4", "5", "6", "7", "8", "9", "Right"))+
  theme(text = element_text(size=20))
p_lrpop

lr <- c(df_bes$lr, df_bes$lr_scale)
lab <- factor(c(rep("Left-Right Scale", length(df_bes$lr)),rep("Alternative Scale", length(df_bes$lr_scale))), levels = c("Left-Right Scale", "Alternative Scale"))

df_lr <- data.frame(lr, lab)

p_lrscales <- ggplot(df_lr, aes(lr)) +
  geom_bar(aes(fill = factor(lab)), alpha = 0.5, color = "black") +
  theme_tufte() +
  scale_x_continuous(breaks = c(0:10)) +
  labs(x="Political Ideology", y="Count") +
  scale_fill_manual(values=c("grey60", "grey15"),  name="Measure")+
  theme(text = element_text(size=20))
p_lrscales
#climateChange enviroGrowth enviroProtection_RBC

df_bes$populism <- as.numeric(df_bes$populism)
df_bes$efficacy <- as.numeric(df_bes$efficacy)
df_bes$auth <- as.numeric(df_bes$auth)

df_dv <- df_bes %>%
  filter(is.na(as.numeric(populism)) == F) %>%
  select(., "climateChange", "enviroGrowth", "enviroProtection_RBC") %>%
  gather(key = "Q", value = "V")

prop.table(table(subset(df_dv, Q == "climateChange")$V))
table(subset(df_dv, Q == "climateChange")$V)
prop.table(table(subset(df_dv, Q == "enviroGrowth")$V))
table(subset(df_dv, Q == "enviroGrowth")$V)
prop.table(table(subset(df_dv, Q == "enviroProtection_RBC")$V))
table(subset(df_dv, Q == "enviroProtection_RBC")$V)


df_dv$V <- factor(df_dv$V, 
                  levels = c("Climate changing due to human activity", "Climate changing but not due to human activity", "Climate not changing", "Don't know",
                             0:10,
                             "Not enough", "About right", "Gone too far", "Don't  know"),
                  labels = c("Climate changing\ndue to\nhuman activity", "Climate changing\nbut not due\nto human activity", "Climate not\nchanging", "Don't\nknow",
                             0:10,
                             "Not enough", "About right", "Gone too far", "Don't \nknow"))

df_dv$Q <- factor(df_dv$Q,
                  levels = c("climateChange", "enviroProtection_RBC", "enviroGrowth"),
                  labels = c("Climate Scepticism", "Support for Env. Protection", "Env. Protection\nvis-a-vis Econ. Growth"))

p_complete <- ggplot(df_dv, aes(V)) +
  geom_bar(fill="white", colour = "black") + 
  facet_grid(~Q, scales = "free") +
  theme(axis.text.x = element_text(angle = 90, vjust=.5)) +
  theme(strip.background = element_rect(fill = 'white')) +
  labs(y="Count", x= "Variable")


p_cc <- ggplot(subset(df_dv, Q == "Climate Scepticism"), aes(V)) +
  geom_bar(fill="white", colour = "black") + 
  #theme(axis.text.x = element_text(angle = 90, vjust=.5)) +
  theme(strip.background = element_rect(fill = 'white')) +
  labs(y="Count", x= "Response")+
  theme(text = element_text(size=20),
        axis.text=element_text(size=14))+
  ggtitle("On the subject of climate change do you think the world's climate ...")
  
p_ep <- ggplot(subset(df_dv, Q == "Support for Env. Protection"), aes(V)) +
  geom_bar(fill="white", colour = "black") + 
  #theme(axis.text.x = element_text(angle = 90, vjust=.5)) +
  theme(strip.background = element_rect(fill = 'white')) +
  labs(y="Count", x= "Response")+
  theme(text = element_text(size=20),
        axis.text=element_text(size=14))+
  ggtitle("Do you think that measures to protect the environment have gone too far or not far enough?")

p_eg <- ggplot(subset(df_dv, Q == "Env. Protection\nvis-a-vis Econ. Growth"), aes(V)) +
  geom_bar(fill="white", colour = "black") + 
  #theme(axis.text.x = element_text( vjust=.5)) +
  theme(strip.background = element_rect(fill = 'white')) +
  labs(y="Count", x= "Response")+
  theme(text = element_text(size=20),
        axis.text=element_text(size=14)) +
  ggtitle("Environmental protection (0) vs. economic growth (10)")

setwd("C:/Users/robhuber/polybox/Research/Populism Attitudes/Populism and Climate Scepticism/Submissions/PSRM/")

ggsave(plot=p_cc, filename="./figs/p_cc.pdf", width = 11.69, height = 6, unit="in")
ggsave(plot=p_ep, filename="./figs/p_ep.pdf", width = 11.69, height = 6, unit="in")
ggsave(plot=p_eg, filename="./figs/p_eg.pdf", width = 11.69, height = 6, unit="in")

p_dvs <- plot_grid(p_cc, p_eG, p_eP, labels = c("A", "B", "C"), align = "h", ncol = 3)

df_cor <- df_bes[c("populism", "lr", "inc", "efficacy", "auth", "age", "econPersonalRetro",  "econGenRetro")]

res <- cor(df_cor, use = "complete.obs")
xtable(round(res, 2))
